package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.TbPower;
import com.ruoyi.system.service.ITbPowerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 权限Controller
 * 
 * @author ruoyi
 * @date 2023-04-23
 */
@RestController
@RequestMapping("/power")
public class TbPowerController extends BaseController
{
    @Autowired
    private ITbPowerService tbPowerService;

    /**
     * 查询权限列表
     */
    @RequiresPermissions("system:power:list")
    @GetMapping("/list")
    public TableDataInfo list(TbPower tbPower)
    {
        startPage();
        List<TbPower> list = tbPowerService.selectTbPowerList(tbPower);
        return getDataTable(list);
    }

    /**
     * 导出权限列表
     */
    @RequiresPermissions("system:power:export")
    @Log(title = "权限", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbPower tbPower)
    {
        List<TbPower> list = tbPowerService.selectTbPowerList(tbPower);
        ExcelUtil<TbPower> util = new ExcelUtil<TbPower>(TbPower.class);
        util.exportExcel(response, list, "权限数据");
    }

    /**
     * 获取权限详细信息
     */
    @RequiresPermissions("system:power:query")
    @GetMapping(value = "/{powerId}")
    public AjaxResult getInfo(@PathVariable("powerId") Long powerId)
    {
        return success(tbPowerService.selectTbPowerByPowerId(powerId));
    }

    /**
     * 新增权限
     */
    @RequiresPermissions("system:power:add")
    @Log(title = "权限", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbPower tbPower)
    {
        return toAjax(tbPowerService.insertTbPower(tbPower));
    }

    /**
     * 修改权限
     */
    @RequiresPermissions("system:power:edit")
    @Log(title = "权限", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbPower tbPower)
    {
        return toAjax(tbPowerService.updateTbPower(tbPower));
    }

    /**
     * 删除权限
     */
    @RequiresPermissions("system:power:remove")
    @Log(title = "权限", businessType = BusinessType.DELETE)
	@DeleteMapping("/{powerIds}")
    public AjaxResult remove(@PathVariable Long[] powerIds)
    {
        return toAjax(tbPowerService.deleteTbPowerByPowerIds(powerIds));
    }
}
